package com.lh.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lh.entity.table.TicketProblemInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;

import java.util.List;

public interface TicketProblemInfoMapper extends BaseMapper<TicketProblemInfo> {

    /**
     * 批量插入工单问题审批数据（MySQL VALUES 语法 + 注解方式）
     * @param list 待插入的工单问题审批实体列表
     * @return 插入成功的记录数
     */
    @Insert("<script>" +
            "INSERT INTO ticket_problem_info (" +
            "  ticket_no, content, risk_level, annex_file, status, is_evaluate, " +
            "  evaluate_content, evaluate_score, remark, title, evaluate_time, " +
            "  prominent_issue, issue_type, issue_category, issue_sub_category, " +
            "  data_resource, resource_description, created_time, complete_deadline, " +
            "  complete_description, applicant_name, applicant_phone_number, " +
            "  process_handler_id, process_handler_department, process_handler_name, " +
            "  process_node_name, end_time, appeal_name, appeal_phone_number, " +
            "  area_name, lead_unit, summary_id, task2_id, lead_check, " +
            "  industry_manager, manager_check, xjb_check, rectification_objective, " +
            "  rectification_measure, acceptance_criteria, participants, meet_deadline, " +
            "  meet_time, actually_participants, score, label, charge_leader, " +
            "  leader_position, warn_level, rectification_id" + // 关键：加上关联的整改ID
            ") VALUES " +
            "<foreach collection='list' item='item' separator=','>" +
            "  (" +
            "    #{item.ticketNo, jdbcType=VARCHAR}, " + // 指定jdbcType，避免null导致的语法错误
            "    #{item.content, jdbcType=VARCHAR}, " +
            "    #{item.riskLevel, jdbcType=VARCHAR}, " +
            "    #{item.annexFile, jdbcType=VARCHAR}, " +
            "    #{item.status, jdbcType=VARCHAR}, " +
            "    #{item.isEvaluate, jdbcType=VARCHAR}, " +
            "    #{item.evaluateContent, jdbcType=VARCHAR}, " +
            "    #{item.evaluateScore, jdbcType=DECIMAL}, " +
            "    #{item.remark, jdbcType=VARCHAR}, " +
            "    #{item.title, jdbcType=VARCHAR}, " +
            "    #{item.evaluateTime, jdbcType=TIMESTAMP}, " +
            "    #{item.prominentIssue, jdbcType=VARCHAR}, " +
            "    #{item.issueType, jdbcType=VARCHAR}, " +
            "    #{item.issueCategory, jdbcType=VARCHAR}, " +
            "    #{item.issueSubCategory, jdbcType=VARCHAR}, " +
            "    #{item.dataResource, jdbcType=VARCHAR}, " +
            "    #{item.resourceDescription, jdbcType=VARCHAR}, " +
            "    #{item.createdTime, jdbcType=TIMESTAMP}, " +
            "    #{item.completeDeadline, jdbcType=TIMESTAMP}, " +
            "    #{item.completeDescription, jdbcType=VARCHAR}, " +
            "    #{item.applicantName, jdbcType=VARCHAR}, " +
            "    #{item.applicantPhoneNumber, jdbcType=VARCHAR}, " +
            "    #{item.processHandlerId, jdbcType=INTEGER}, " +
            "    #{item.processHandlerDepartment, jdbcType=VARCHAR}, " +
            "    #{item.processHandlerName, jdbcType=VARCHAR}, " +
            "    #{item.processNodeName, jdbcType=VARCHAR}, " +
            "    #{item.endTime, jdbcType=TIMESTAMP}, " +
            "    #{item.appealName, jdbcType=VARCHAR}, " +
            "    #{item.appealPhoneNumber, jdbcType=VARCHAR}, " +
            "    #{item.areaName, jdbcType=VARCHAR}, " +
            "    #{item.leadUnit, jdbcType=VARCHAR}, " +
            "    #{item.summaryId, jdbcType=INTEGER}, " +
            "    #{item.task2Id, jdbcType=INTEGER}, " +
            "    #{item.leadCheck, jdbcType=VARCHAR}, " +
            "    #{item.industryManager, jdbcType=VARCHAR}, " +
            "    #{item.managerCheck, jdbcType=VARCHAR}, " +
            "    #{item.xjbCheck, jdbcType=VARCHAR}, " +
            "    #{item.rectificationObjective, jdbcType=VARCHAR}, " +
            "    #{item.rectificationMeasure, jdbcType=VARCHAR}, " +
            "    #{item.acceptanceCriteria, jdbcType=VARCHAR}, " +
            "    #{item.participants, jdbcType=VARCHAR}, " +
            "    #{item.meetDeadline, jdbcType=VARCHAR}, " +
            "    #{item.meetTime, jdbcType=TIMESTAMP}, " +
            "    #{item.actuallyParticipants, jdbcType=VARCHAR}, " +
            "    #{item.score, jdbcType=DECIMAL}, " +
            "    #{item.label, jdbcType=VARCHAR}, " +
            "    #{item.chargeLeader, jdbcType=VARCHAR}, " +
            "    #{item.leaderPosition, jdbcType=VARCHAR}, " +
            "    #{item.warnLevel, jdbcType=VARCHAR}, " +
            "    #{item.rectificationId, jdbcType=INTEGER}" + // 关键：传入整改ID，避免该字段为null
            "  )" +
            "</foreach>" +
            "</script>")
    int batchInsertByAnnotation(@Param("list") List<TicketProblemInfo> list);
}
